using Godot;
using System;

public partial class MessageWarning : Control
{
	Label label;
	Timer timer;

	public override void _Ready()
	{
		label = GetNode<Label>("LabelMessage");
		timer = GetNode<Timer>("Timer");
		timer.Timeout += OnTimerTimeout;
	}

	bool timeout = false;
	private void OnTimerTimeout()
	{
		timeout = true;
		tween = CreateTween();
		tween.TweenProperty(label, "position", new Vector2(300, 0), 0.2);
		tween.Finished += OnTweenFinished;
	}

	private void OnTweenFinished()
	{
		if (timeout)
		{
			QueueFree();
		}
	}

	Tween tween;
	public void ShowMessage(string message)
	{
		label.Text = message;
		tween = CreateTween();
		tween.TweenProperty(label, "position", Vector2.Zero, 0.2);
	}
}
